<%@ Language=VBScript%>
<% 
	Session("FormName")="F12"
%>
<!--#include file="..\CheckSession.inc"-->
<!--#include file=..\getFormName.inc-->
<html>
<head>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>New Page 2</title>
</head>
<!--#include file="..\jvGrid.inc"-->
<!--#include file=..\vbFunction.inc-->
<!--#include file="..\pageSelected.inc"-->
<%	
	btest=session("TopNum")
	Set ClsFun=server.CreateObject("Vinalines.ClsFunction")
	Dim bLink 
	mode=Request("mode")
	bComm=Request("bComm")
	bMa=Request("bMa")
	bMacu=Request("bMacu")

	if bComm="detail" then		
		bMa=Request("bMa")
		bMacu=Request("bMacu")
		sSQL="Select * from Nhom where manhom Like '"& bMa &"'"
		Set RecDL=server.CreateObject("ADODB.Recordset")
		RecDL.CursorType=3
		RecDL.CacheSize=5
		RecDL.Open sSQL,Conn
		if RecDL.RecordCount then	
			bTen=RecDL("Tennhom")
			bTencu=RecDL("Tennhom")
			bngaytl=RecDL("ngaythanhlap")
			bngaygt=RecDL("ngaygiaitan")
			Loaitim=Request("Loaitim")
			bsearch=Request("bsearch")
			bSoTT=trim(RecDL("STT"))
			bKyvanban=RecDL("Kyvanban")
		end if
		RecDL.Close
		set RecDL=nothing
		Session("bManhom")=bMa
		Session("bTenNhom")=bTen
	else
		bTen=Request("bTen")
		bTencu=Request("bTencu")
		bngaytl=request("bngaytl")
		bngaygt=request("bngaygt")
		Loaitim=request("Loaitim")
		bsearch=request("bsearch")
		bSoTT=trim(Request("bSoTT"))
		bKyvanban=Request("Kyvanban")
		if bKyvanban="ON" then
			bKyvanban=1
		else
			bKyvanban=0
		end if
	end if	
	Dim bTempComm
	Dim bMsg
	Dim Msg	
		if Session("ClsFun").LayGiaTriQuyen(Session("Permision"),Session("FormName"),2)="1" or Session("IsAdmin") then	
		Select Case bComm
			Case "add"
				if not KTMa(bMa,bComm) then
					if not KTTen(bTen,bComm) then
						if trim(bngaygt)="" and trim(bngaytl)="" then
							sSQL="Insert into nhom(STT,manhom,tennhom,ngaythanhlap,ngaygiaitan,Kyvanban)values('"& ClsFun.ModiString(bSoTT) &"','"& ClsFun.ModiString(bMa) &"','"& ClsFun.ModiString(bTen) &"',NULL,NULL,"& bKyvanban &")"
						end if
						if trim(bngaygt)<>"" and trim(bngaytl)<>"" then
							sSQL="Insert into nhom(STT,manhom,tennhom,ngaythanhlap,ngaygiaitan,Kyvanban)values('"& ClsFun.ModiString(bSoTT) &"','"& ClsFun.ModiString(bMa) &"','"& ClsFun.ModiString(bTen) &"','"& ClsFun.SaveDate(bngaytl) &"','"& ClsFun.SaveDate(bngaygt) &"',"& bKyvanban &")"						
						end if
						if trim(bngaygt)<>"" and trim(bngaytl)="" then
							sSQL="Insert into nhom(STT,manhom,tennhom,ngaythanhlap,ngaygiaitan,Kyvanban)values('"& ClsFun.ModiString(bSoTT) &"','"& ClsFun.ModiString(bMa) &"','"& ClsFun.ModiString(bTen) &"',NULL,'"& ClsFun.SaveDate(bngaygt) &"',"& bKyvanban &")"						
						end if
						if trim(bngaygt)="" and trim(bngaytl)<>"" then
							sSQL="Insert into nhom(STT,manhom,tennhom,ngaythanhlap,ngaygiaitan,Kyvanban)values('"& ClsFun.ModiString(bSoTT) &"','"& ClsFun.ModiString(bMa) &"','"& ClsFun.ModiString(bTen) &"','"& ClsFun.SaveDate(bngaytl) &"',NULL,"& bKyvanban &")"
						end if					
						Conn.Execute sSQL					
					else
						Msg="T&#234;n &#273;&#227; t&#7891;n t&#7841;i"
						bMsg="ten"
					end if
				else
					Msg="T&#234;n &#273;&#227; t&#7891;n t&#7841;i"
					bMsg="ma"
				end if
			case "delete"	
				set RecKT=server.CreateObject("ADODB.Recordset")
				RecKT.CursorType=3
				RecKT.CacheSize=5
				ssql="Select manhom from canbo_nhom where manhom like '"& ClsFun.ModiString(bma) &"'"
				RecKT.Open ssql,Conn
				if RecKT.RecordCount<=0 then
					set RecPhone=server.CreateObject("ADODB.Recordset")
					RecPhone.CursorType=3
					RecPhone.CacheSize=5
					ssql="Select * from Phone where IDNhom like '"& ClsFun.ModiString(bma) &"'"
					RecPhone.Open ssql,Conn
					if RecPhone.RecordCount<=0 then
						set RecKTDC=server.CreateObject("ADODB.Recordset")
						RecKTDC.CursorType=3
						RecKTDC.CacheSize=5
						ssql="Select diachi from diachiluutru where diachi like '"& ClsFun.ModiString(bma) &"'"
						RecKTDC.Open ssql,Conn
						if RecKTDC.RecordCount<=0 then						
							set RecQuyen=server.CreateObject("ADODB.Recordset")
							RecQuyen.CursorType=3
							RecQuyen.CacheSize=5
							ssql="Select * from Quyen_nhom where manhom like '"& ClsFun.ModiString(bma) &"'"
							RecQuyen.Open ssql,Conn
							if RecQuyen.RecordCount<=0 then
								RecQuyen.close
								ssql="Select * from Don_VI_SOAN where IDnhom like '"& ClsFun.ModiString(bma) &"'"
								RecQuyen.Open ssql,Conn
								if RecQuyen.RecordCount<=0 then
									sSQL="Delete from nhom Where manhom Like '"& ClsFun.ModiString(bMa) &"'"
									Conn.Execute sSQL	
								else
									Msg="Nh&#243;m &#273;ang li&#234;n k&#7871;t v&#7899;i Nh&#243;m kh&#244;ng th&#7875; xo&#225; &#273;&#432;&#7907;c!"				
								end if
							else
								Msg="Nh&#243;m &#273;ang li&#234;n k&#7871;t v&#7899;i Nh&#243;m kh&#244;ng th&#7875; xo&#225; &#273;&#432;&#7907;c!"
							end if
						else
							Msg="Nh&#243;m &#273;ang li&#234;n k&#7871;t v&#7899;i &#273;&#7883;a ch&#7881; l&#432;u tr&#7919; kh&#244;ng th&#7875; xo&#225; &#273;&#432;&#7907;c!"
						end if
						RecKTDC.Close
						Set RecKTDC=nothing
					else
						Msg="Nh&#243;m &#273;ang li&#234;n k&#7871;t v&#7899;i danh b&#7841; &#273;i&#7879;n tho&#7841;i kh&#244;ng th&#7875; xo&#225; &#273;&#432;&#7907;c!"
					end if				
					RecPhone.Close
					Set RecPhone=nothing
				else				
					Msg="Nh&#243;m &#273;ang ch&#7913;a c&#225;n b&#7897; kh&#244;ng th&#7875; xo&#225; &#273;&#432;&#7907;c !"				
				end if
				RecKT.Close
				set RecKT=nothing
			case "edit"
				if not KTMa(bMa,"edit") then
					'Neu ma thay doi
					if lcase(bmacu)<>lcase(bma) then 
						sSQL="Select * from canbo_nhom where manhom like '"& ClsFun.ModiString(bMacu) &"'"
						Set RecT=Server.CreateObject("ADODB.Recordset")
						RecT.CursorType=3
						RecT.CacheSize=5
						RecT.Open sSQL,Conn
						if RecT.RecordCount>0 then
							Msg="M&#227; &#273;ang &#273;&#432;&#7907;c li&#234;n k&#7871;t kh&#244;ng th&#7875; thay &#273;&#7893;i"
							bMsg="malienket"
						else	
							RecT.close			
							sSQL="Select * from Quyen_nhom where manhom like '"& ClsFun.ModiString(bMacu) &"'"
							RecT.CursorType=3
							RecT.CacheSize=5
							RecT.Open sSQL,Conn
							if RecT.RecordCount>0 then
								Msg="M&#227; &#273;ang &#273;&#432;&#7907;c li&#234;n k&#7871;t kh&#244;ng th&#7875; thay &#273;&#7893;i"
								bMsg="malienket"
							else										
								if not KTTen(bTen,"edit") then
									if trim(bngaygt)="" and trim(bngaytl)="" then
										sSQL="Update nhom set STT='"& ClsFun.ModiString(bSoTT) _
												&"',manhom='"& ClsFun.ModiString(bma) _
												&"',tennhom='"& ClsFun.ModiString(bTen) _
												&"',ngaythanhlap=NULL,ngaygiaitan=NULL,Kyvanban= "& bKyvanban &" Where manhom Like '" & ClsFun.ModiString(bMacu) & "'"
									end if
									if trim(bngaygt)<>"" and trim(bngaytl)<>"" then
										sSQL="Update nhom set STT='"& ClsFun.ModiString(bSoTT) _
												&"',manhom='"& ClsFun.ModiString(bma) _
												&"',tennhom='"& ClsFun.ModiString(bTen) _
												&"',ngaythanhlap='"& ClsFun.SaveDate(bngaytl) _
												&"',ngaygiaitan='"& ClsFun.SaveDate(bngaygt) _
												&"' ,Kyvanban= "& bKyvanban &" Where manhom Like '" & ClsFun.ModiString(bMacu) & "'"
									end if
									if trim(bngaygt)<>"" and trim(bngaytl)="" then
										sSQL="Update nhom set STT='"& ClsFun.ModiString(bSoTT) _
												&"',manhom='"& ClsFun.ModiString(bma) _
												&"',tennhom='"& ClsFun.ModiString(bTen) _
												&"',ngaythanhlap=NULL,ngaygiaitan='"& ClsFun.SaveDate(bngaygt) _
												&"' ,Kyvanban= "& bKyvanban &" Where manhom Like '" & ClsFun.ModiString(bMacu) & "'"
									end if
									if trim(bngaygt)="" and trim(bngaytl)<>"" then
										sSQL="Update nhom set STT='"& ClsFun.ModiString(bSoTT) _
												&"',manhom='"& ClsFun.ModiString(bma) _
												&"',tennhom='"& ClsFun.ModiString(bTen) _
												&"',ngaythanhlap='"& ClsFun.SaveDate(bngaytl) _
												&"',ngaygiaitan=NULL,Kyvanban= "& bKyvanban &" Where manhom Like '" & ClsFun.ModiString(bMacu) & "'"
									end if
									Conn.Execute sSQL			
									sSQL="Update Dangkylich set manhom ='"& ClsFun.ModiString(bma) &"' Where manhom Like '" & ClsFun.ModiString(bMacu) & "'"
									Conn.Execute sSQL			
									sSQL="Update Phone set IDNhom ='"& ClsFun.ModiString(bma) &"' Where IDNhom Like '" & ClsFun.ModiString(bMacu) & "'"
									Conn.Execute sSQL
								else
									Msg="T&#234;n &#273;&#227; T&#7891;n t&#7841;i"
									bMsg="ten"
								end if
							end if
						end if
						RecT.Close
						Set RecT=nothing
					else 'ma khong thay doi
						if not KTTen(bTen,"edit") then
								if trim(bngaygt)="" and trim(bngaytl)="" then
									sSQL="Update nhom set STT='"& ClsFun.ModiString(bSoTT) _
												&"',tennhom='"& ClsFun.ModiString(bTen) _
											&"',ngaythanhlap=NULL,ngaygiaitan=NULL,Kyvanban= "& bKyvanban &" Where manhom Like '" & ClsFun.ModiString(bMacu) & "'"
								end if
								if trim(bngaygt)<>"" and trim(bngaytl)<>"" then
									sSQL="Update nhom set STT='"& ClsFun.ModiString(bSoTT) _
												&"',tennhom='"& ClsFun.ModiString(bTen) _
											&"',ngaythanhlap='"& ClsFun.SaveDate(bngaytl) _
											&"',ngaygiaitan='"& ClsFun.SaveDate(bngaygt) _
											&"' ,Kyvanban= "& bKyvanban &" Where manhom Like '" & ClsFun.ModiString(bMacu) & "'"
								end if
								if trim(bngaygt)<>"" and trim(bngaytl)="" then
									sSQL="Update nhom set STT='"& ClsFun.ModiString(bSoTT) _
												&"',tennhom='"& ClsFun.ModiString(bTen) _
											&"',ngaythanhlap=NULL,ngaygiaitan='"& ClsFun.SaveDate(bngaygt) _
											&"' ,Kyvanban= "& bKyvanban &" Where manhom Like '" & ClsFun.ModiString(bMacu) & "'"
								end if
								if trim(bngaygt)="" and trim(bngaytl)<>"" then
									sSQL="Update nhom set STT='"& ClsFun.ModiString(bSoTT) _
												&"',tennhom='"& ClsFun.ModiString(bTen) _
											&"',ngaythanhlap='"& ClsFun.SaveDate(bngaytl) _
											&"',ngaygiaitan=NULL,Kyvanban= "& bKyvanban &" Where manhom Like '" & ClsFun.ModiString(bMacu) & "'"
								end if
						
	'							sSQL="Update nhom set STT='"& ClsFun.ModiString(bSoTT) _
	'								&"',tennhom='"& ClsFun.ModiString(bTen) _
	'								&"',ngaythanhlap='"& ClsFun.SaveDate(bngaytl) _
	'								&"',ngaygiaitan='"& ClsFun.SaveDate(bngaygt) _
	'								&"' Where manhom Like '" & ClsFun.ModiString(bMacu) & "'"
							Conn.Execute sSQL			
						else
							Msg="T&#234;n &#273;&#227; T&#7891;n t&#7841;i"
							bMsg="ten"
						end if
					end if
				else 
					Msg="M&#227; &#273;&#227; T&#7891;n t&#7841;i"
					bMsg="ma"
				end if
		End Select
	End if
	Set Rec=server.CreateObject("ADODB.Recordset") 
	rec.CursorType = 3
	rec.CacheSize=5		
	select case Request("bComm")
		case "search"	
			ssql="Select * from nhom where tennhom like '%"& ClsFun.ModiString(bsearch) & "%' order by manhom"
		case else
			Loaitim=""
			bsearch=""
			ssql="Select * from nhom  order by manhom"
	end select
	Dim nRecCount	' Number of records found
	Dim nPageCount	' Number of pages of records we have
	Dim nPage	' Current page number
	nPage=CLng(request("Page"))	
	if nPage="" then nPage=1
	rec.Open ssql,Conn
	if  rec.EOF and rec.BOF then
		nPageCount=0
	end if	
%>
<%if Msg<>"" then%>
  <% if bMsg="ma" then %>
			<center><font size=3 color=red face='Times New Roman'>M&#227; nh&#243;m: <%=bma%> &#273;&#227; t&#7891;n t&#7841;i</font></center>
   <%end if%>
  <% if bMsg="ten" then %>
			<center><font size=3 color=red face='Times New Roman'>T&#234;n: <%=bten%> &#273;&#227; t&#7891;n t&#7841;i</font></center>
   <%end if%>
   <% if bMsg="malienket" then %>
			<center><font size=3 color=red face='Times New Roman'><%=Msg%></font></center>
   <%end if%>
   <% if bMsg="" then %>
			<center><font size=3 color=red face='Times New Roman'><%=Msg%></font></center>
   <%end if%>
<%end if%>
<!--#include file="..\jvfunction.inc"-->
<script language=VBScript runat=server>
	'Kiem tra ma trung
	Function KTMa(bValue,loai)
		KTMa=false
		if loai="add" then
			ssql="Select * from nhom where Manhom like '"& trim(ClsFun.ModiString(bValue)) &"'"
			Set RecTemp=server.CreateObject("ADODB.Recordset") 
			RecTemp.Open ssql,Application("StrConn")
			if (not rectemp.BOF) and (not RecTemp.EOF) then
				KTMa=True
			end if
			set RecTemp=nothing
		end if
		if loai="edit" then
			if Lcase(bMacu)<>Lcase(bValue) then
				ssql="Select * from nhom where Manhom like '"& trim(ClsFun.ModiString(bValue)) &"'"
				Set RecTemp=server.CreateObject("ADODB.Recordset") 
				RecTemp.Open ssql,Application("StrConn")
				if (not rectemp.BOF) and (not RecTemp.EOF) then
					KTMa=True
				end if
				set RecTemp=nothing
			end if		
		end if
	End function
	'Kiem tra ten trung
	Function KTTen(bValue,loai)
		KTTen=false
		if loai="add" then
			ssql="Select Tennhom from nhom where Tennhom like '"& trim(ClsFun.ModiString(bValue)) &"'"
			Set RecTemp=server.CreateObject("ADODB.Recordset") 
			RecTemp.Open ssql,Application("StrConn")
			if (not rectemp.BOF) and (not RecTemp.EOF) then
				KTTen=True
			end if
			set RecTemp=nothing
		end if
		if loai="edit" then
			if Lcase(bTencu)<>Lcase(bValue) then
				ssql="Select Tennhom from nhom where tennhom like '"& trim(ClsFun.ModiString(bValue)) &"'"
				Set RecTemp=server.CreateObject("ADODB.Recordset") 
				RecTemp.Open ssql,Application("StrConn")
				if (not rectemp.BOF) and (not RecTemp.EOF) then
					KTTen=True
				end if
				set RecTemp=nothing
			end if		
		end if
	End function
	'Kiem tra truoc khi Xoa ban ghi co quan he voi bang khac khong
	Function KTQuanhe(bValue,TableName)
		KTQuanhe=false
	End Function
Function Paging(ByVal intPage, ByVal intPageCount, ByVal intRecordCount)
	Dim strQueryString
	Dim strScript
	Dim intStart
	Dim intEnd
	Dim strRet
	Dim i

	If intPage > intPageCount Then
		intPage = intPageCount
	ElseIf intPage < 1 Then 
		intPage = 1
	End If
	
	If intRecordCount = 0 Then
		'strRet = "No Records Found"
	ElseIf intPageCount = 1 Then
		'strRet = "End Of Hits"
	Else
		For i = 1 To Request.QueryString.Count
			If LCase(Request.QueryString.Key(i)) <> "page" Then
				strQueryString = strQueryString & "&" 
				strQueryString = strQueryString & Server.URLEncode(Request.QueryString.Key(i)) & "=" 
				strQueryString = strQueryString & Server.URLEncode(Request.QueryString.Item(i))
			End If
		Next

		For i = 1 To Request.Form.Count
			If LCase(Request.Form.Key(i)) <> "page" Then
				strQueryString = strQueryString & "&" 
				strQueryString = strQueryString & Server.URLEncode(Request.Form.Key(i)) & "=" 
				strQueryString = strQueryString & Server.URLEncode(Request.Form.Item(i))
			End If
		Next

		If Len(strQueryString) <> 0 Then
			strQueryString = "?" & Mid(strQueryString, 2) & "&"
		Else
			strQueryString = "?"
		End If

		strScript = Request.ServerVariables("SCRIPT_NAME") & strQueryString
	
		If intPage <= 10 Then
			intStart = 1
		Else
			If (intPage Mod 10) = 0 Then
				intStart = intPage - 9
			Else
				intStart = intPage - (intPage Mod 10) + 1
			End If
		End If

		intEnd = intStart + 9
		If intEnd > intPageCount Then intEnd = intPageCount
	
		'strRet = "Page " & intPage & " of " & intPageCount & ": "
	
		If intPage > 10 Then 
			strRet = strRet & "<a href=""" & strScript
			strRet = strRet & "page=" & intPage - 10 
			strRet = strRet & """><IMG border=0 SRC=../images/prev.gif></a> "
		End If
	
		For i = intStart To intEnd
			If i = intPage Then
				strRet = strRet & "<b><font color=A90A08>" & i & "</font></b> "
			Else
				strRet = strRet & "<a href=""" & strScript
				strRet = strRet & "page=" & i 
				strRet = strRet & """>" & i & "</a>"
				If i <> intEnd Then strRet = strRet & " "
			End If
		Next
	
		If intPage <> intPageCount and intPageCount > 10 Then
			strRet = strRet & " <a href=""" & strScript
			strRet = strRet & "page=" & intPage + 10 
			strRet = strRet & """><IMG border=0 SRC=../images/next.gif></a> "
		End If
	End If
	
	Paging = strRet
End Function
</script>

<script language=VBScript  runat="server">
</script>

<SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
<!--
function ChangePage(){
	strURL= nhom.page.value;
	window.nhom.target="right";
	window.nhom.action=strURL;
	window.nhom.submit();
}

function KTNhap(){
	if (nhom.TxtMa.value==""){
		alert("Bạn cần phải nhập mã");
		nhom.TxtNgayTL.focus();
		return false;
	}
	if(daucach(nhom.TxtMa.value)){
		alert("Mã không cho phép chứa ký tự đặc biệt (',space)");
		nhom.TxtMa.focus();
		return false;
	}
	if (nhom.TxtTen.value==""){
		alert("Bạn cần phải nhập tên");
		nhom.TxtTen.focus();
		return false;
	}
	if(trim(nhom.TxtNgayTL.value)!=""){
		if (!isDate(nhom.TxtNgayTL.value)){
			alert("Ngày không hợp lệ");
			nhom.TxtNgayTL.focus();
			return false;
		}
	}
	if(trim(nhom.TxtNgayGT.value)!=""){
		if (!isDate(nhom.TxtNgayGT.value)){
			alert("Ngày không hợp lệ");
			nhom.TxtNgayGT.focus();
			return false;
		}
	}
	return true;
}

function CmdAdd_onclick() {
//	nhom.TxtSoTT.value="";
	nhom.TxtMa.value="<%=TaoMa("manhom","nhom")%>"
	//nhom.TxtMa.value="";
	nhom.TxtTen.value="";
	nhom.TxtNgayGT.value="";
	nhom.TxtNgayTL.value="";
	nhom.CmdPhannhom.disabled=true;
	cmdenable(false);
	Unlockdata();
//	nhom.TxtSoTT.focus();
	nhom.TxtNgayTL.focus();
	nhom.sua.value="2";
	nhom.Kyvanban.checked=false;	
}
function cmdenable(bvalue){
	if (bvalue){
		if ("<%= Session("ClsFun").LayGiaTriQuyen(Session("Permision"),Session("FormName"),2)%>"=='1'||"<%= Session("IsAdmin") %>".toLowerCase()=='true'){
			nhom.CmdAdd.disabled= false;
		}			
		else{
			nhom.CmdAdd.disabled= true;		
		}	
		nhom.CmdDelete.disabled= false;
		nhom.CmdEdit.disabled= false;
		//nhom.CmdPhannhom.disabled=false;
		nhom.CmdSearch.disabled=false;
		
		nhom.CmdCancel.disabled= true;
		nhom.CmdOK.disabled= true;	
	}
	else {
		nhom.CmdAdd.disabled= true;
		nhom.CmdDelete.disabled= true;
		nhom.CmdEdit.disabled= true;
		//nhom.CmdPhannhom.disabled=true;
		nhom.CmdSearch.disabled=true;
		
		nhom.CmdCancel.disabled= false;
		nhom.CmdOK.disabled= false;
	}	
	nhom.CmdSearch.value="Tì<u>m</u> kiếm";
}

function CmdCancel_onclick() {
	cmdenable(true);
	nhom.CmdDelete.disabled= true;
	nhom.CmdEdit.disabled= true;
	Lockdata();
	nhom.TxtNgayGT.value="";
	nhom.TxtNgayTL.value="";
	nhom.TxtTen.value="";
	nhom.TxtMa.value=""
//	nhom.TxtSoTT.value=""
}

function Lockdata(){
//	nhom.TxtSoTT.disabled=true;
	nhom.TxtMa.disabled=true;
	nhom.Kyvanban.disabled=true;
	nhom.TxtNgayGT.disabled=true;
	nhom.TxtNgayTL.disabled=true;
	nhom.TxtTen.disabled=true;
}
function Unlockdata(){
//	nhom.TxtSoTT.disabled=false;
	nhom.TxtMa.disabled=false;
	nhom.TxtNgayGT.disabled=false;
	nhom.TxtNgayTL.disabled=false;
	nhom.TxtTen.disabled=false;
	nhom.Kyvanban.disabled=false;
}
function window_onload() {
//	CmdCancel_onclick();	
}	

function CmdExit_onclick() {
//	window.navigate("<%= Session("LastForm")%>");
}
function CmdDelete_onclick() {
	if (nhom.TxtMa.value==""){
		alert("Bạn hãy chọn thông tin cần xóa");
		return ;
	}
	if(!confirm("Bạn có muốn xóa không ?")){
		return false;	
	}
	ma=nhom.TxtMa.value;
	cp=nhom.cPage.value
	b="frmnhom.asp?Page="+cp+"&bma="+ma+"&bComm=delete"					
	window.nhom.target="right"
	window.nhom.action=b;
	window.nhom.submit();
	//window.navigate(b);
}
function CmdEdit_onclick() {
	if (nhom.TxtMa.value==""){
		alert("Bạn hãy chọn thông tin cần sửa");
		return ;
	}
	nhom.CmdPhannhom.disabled=true;
	cmdenable(false);
	Unlockdata();
//	nhom.TxtSoTT.focus();
	<%bTempComm="edit"%>
	nhom.sua.value="1";
	nhom.Macu.value=nhom.TxtMa.value;
	nhom.Tencu.value=nhom.TxtTen.value
}
function CmdOK_onclick() {
	if (KTNhap()){
		cmdenable(true);
		//Lockdata();
		ma=nhom.TxtMa.value;
		ten=nhom.TxtTen.value;
		ngaygt=nhom.TxtNgayGT.value;
		ngaytl=nhom.TxtNgayTL.value;
		macu=nhom.Macu.value;
		tencu=nhom.Tencu.value;
		bc=nhom.sua.value;
		cp=nhom.cPage.value;
//		bSoTT=nhom.TxtSoTT.value;
		if (bc=="1"){
			b="frmnhom.asp?Page="+cp+"&bMacu="+macu+"&bTencu="+tencu+"&bma="+ma+"&bTen="+ten+"&bngaygt="+ngaygt+"&bSoTT=&bngaytl="+ngaytl+"&bComm=edit"		
		}
		if(bc=="2") {
			b="frmnhom.asp?Page="+cp+"&bma="+ma+"&bTen="+ten+"&bngaygt="+ngaygt+"&bngaytl="+ngaytl+"&bSoTT=&bComm=add"					
		}
		window.nhom.target="right"
		window.nhom.action=b;
		window.nhom.submit();
		//window.navigate(b);
	}
}
function CmdLoc_onclick() {
	Unlockdata();
	nhom.TxtMa.focus();
//	nhom.sua.value="2";
}


function CmdPhannhom_onclick() {
	if(nhom.TxtMa.value==""){
		alert("Bạn cần phải chọn nhóm");
		return false;
	}	
	//window.nhom.target="main";
	window.nhom.target="right";
	parent.vbalFrameset.cols = "0,6,*";
	ma=nhom.TxtMa.value;
	ten=nhom.TxtTen.value;
	nhom.action="phannhom/frmphannhom.asp";
	nhom.submit();
}
	

function window_onload() {
	
}

function TxtSearch_onclick() {
}

function CmdSearch_onclick() {
	nhom.CmdAdd.disabled=true;
	nhom.CmdCancel.disabled=false;
	nhom.CmdEdit.disabled=true;
	nhom.CmdDelete.disabled=true;
	nhom.CmdPhannhom.disabled=true;
	if (nhom.TxtTen.disabled){
		nhom.CmdSearch.value="Tì<u>m</u>";
		Unlockdata()
//		nhom.TxtSoTT.value="";
		nhom.TxtMa.value="";
		nhom.TxtNgayGT.value="";
		nhom.TxtNgayTL.value="";
		nhom.TxtTen.value="";
		Lockdata();
		nhom.TxtTen.disabled=false;
		nhom.TxtTen.value="";
		nhom.TxtTen.focus();
		return false;
	}
	value=nhom.TxtTen.value;
	blink="frmnhom.asp?bsearch="+value+"&bComm=search";
	window.nhom.action=blink;
	window.nhom.target="right"
	window.nhom.submit();
}

function CmdPrint_onclick() {
	window.nhom.target="new";
	window.nhom.action="../in/frmin.asp?bIn=nhom";
	window.nhom.submit();
}
function CmdALL_onclick(){
	nhom.target="right";
	nhom.action="frmnhom.asp";
	nhom.submit();
}

function TxtNgayTL_onkeyup(str){
var keycode
keycode=window.event.keyCode
if (isEdit(keycode,str)){
	nhom.TxtNgayTL.value=editdate(trim(str))
}
}

function TxtNgayGT_onkeyup(str){
var keycode
keycode=window.event.keyCode
if (isEdit(keycode,str)){
	nhom.TxtNgayGT.value=editdate(trim(str))
}
}

function SetFocus(){
	document.nhom.CmdSearch.focus();
	
}
//-->
</SCRIPT>
<LINK href="../styles/styles.css" type=text/css rel=STYLESHEET>
<body  bgcolor=#F8F9D9 topmargin="0" leftmargin="0" style="font-family:times new roman" onload="SetFocus()">
<form name="nhom" method="post">
	<input type="hidden" name="sua" value="">
	<input type="hidden" name="Macu" value="">
	<input type="hidden" name="Tencu" value="">
	<input type="hidden" name="cPage" value="<%=nPage%>">
	<input type="hidden" name="strURL" value="">
<p align=center><b><font FACE="Times New Roman" size="3">CẬP NHẬT NHÓM LÀM VIỆC</font></b>
<table border="0" cellpadding="0" cellspacing="0" style="BORDER-BOTTOM-STYLE: none; BORDER-LEFT-STYLE: solid; BORDER-RIGHT-STYLE: solid; BORDER-TOP-STYLE: solid;border-collapse:collapse; border-left-color:#C0C0C0; border-right-color:#C0C0C0; border-top-color:#C0C0C0; border-bottom-color:#C0C0C0" width="100%" bgcolor="#BDD5D0" bordercolor="#111111">
  <tr>
	<% if Session("ClsFun").LayGiaTriQuyen(Session("Permision"),Session("FormName"),2)="1" or Session("IsAdmin") then	%>
			<td width="12%">
				<Button name="CmdAdd" style="FONT-FAMILY: Arial;WIDTH: 100%" LANGUAGE=javascript onclick="return CmdAdd_onclick()" accesskey="T"><U>T</U>hêm</Button></td>
	    <%if  bcomm<>"detail" then%>
			<td width="12%">
				<Button disabled  name="CmdDelete" style="FONT-FAMILY: Arial; WIDTH: 100%" LANGUAGE=javascript onclick="return CmdDelete_onclick()" accesskey="X"><U>X</U>óa</Button></td>
		    <td width="12%">
		    		<Button disabled  name="CmdEdit" style="FONT-FAMILY: Arial;WIDTH: 100%" LANGUAGE=javascript onclick="return CmdEdit_onclick()" accesskey="S"><U>S</U>ửa</button></td>
		<%else%>
			<td width="12%">
				<Button name="CmdDelete" style="FONT-FAMILY: Arial; WIDTH: 100%" LANGUAGE=javascript onclick="return CmdDelete_onclick()" accesskey="X"><U>X</U>óa</Button></td>
		    <td width="12%">
		    		<Button name="CmdEdit" style="FONT-FAMILY: Arial;WIDTH: 100%" LANGUAGE=javascript onclick="return CmdEdit_onclick()" accesskey="S"><U>S</U>ửa</Button></td>
		<%end if%>
			<td width="12%">
				<Button name="CmdOK" disabled=true style="FONT-FAMILY: Arial;WIDTH: 100%" LANGUAGE=javascript onclick="return CmdOK_onclick()" accesskey="G"><P><U>G</U>hi nhận</P></Button></td>
		    <td width="13%">
		    		<Button name="CmdCancel" disabled=true style="FONT-FAMILY: Arial;WIDTH: 100%" LANGUAGE=javascript onclick="return CmdCancel_onclick()" accesskey="B"><P><U>B</U>ỏ qua</P></Button></td>
		    <td width="13%">
		    		<Button name="CmdSearch" style="FONT-FAMILY: Arial;WIDTH: 100%" LANGUAGE=javascript onclick="return CmdSearch_onclick()" accesskey="M"><P>Tì<u>m</u> kiếm</P> </Button></td>
	    <%if  bcomm<>"detail" then%>
    		<td width="13%">
    			<Button disabled name="CmdPhannhom" Style="FONT-FAMILY:Arial;WIDTH: 100%" LANGUAGE=javascript onclick="return CmdPhannhom_onclick()" accesskey="P"><P><U>P</U>hân nhóm</P></Button></td>
		<%else%>
			<% if Session("ClsFun").LayGiaTriQuyen(Session("Permision"),Session("FormName"),3)="1" or Session("IsAdmin") then	%>
				<td width="13%">
					<Button  name="CmdPhannhom" style="FONT-FAMILY:Arial;WIDTH: 100%" LANGUAGE=javascript onclick="return CmdPhannhom_onclick()" accesskey="P"><P><U>P</U>hân nhóm</P></Button></td>
			<%else%>
	    		<td width="13%">
	    				<Button disabled name="CmdPhannhom" Style="FONT-FAMILY:Arial;WIDTH: 100%" LANGUAGE=javascript onclick="return CmdPhannhom_onclick()" accesskey="P"><P><U>P</U>hân nhóm</P></Button></td>				
			<%end if%>		
		<%end if%>
	<%else%>
		<td width="12%"><Button disabled name="CmdAdd" style="FONT-FAMILY: Arial;WIDTH: 100%" LANGUAGE=javascript onclick="return CmdAdd_onclick()" accesskey="T"><U>T</U>hêm</Button></td>
		<td width="12%"><Button disabled name="CmdDelete" style="FONT-FAMILY: Arial; WIDTH: 	100%" LANGUAGE=javascript onclick="return CmdDelete_onclick()" accesskey="X"><U>X</U>óa</Button></td>
		<td width="12%"><Button disabled name="CmdEdit" style="FONT-FAMILY: Arial;WIDTH: 100%" LANGUAGE=javascript onclick="return CmdEdit_onclick()" accesskey="S"><U>S</U>ửa</Button></td>
		<td width="12%"><Button name="CmdOK" disabled=true style="FONT-FAMILY: Arial;WIDTH: 100%" LANGUAGE=javascript onclick="return CmdOK_onclick()" accesskey="G"><P><U>G</U>hi nhận</P></Button></td>
		<td width="13%"><Button name="CmdCancel" disabled=true style="FONT-FAMILY: Arial;WIDTH: 100%" LANGUAGE=javascript onclick="return CmdCancel_onclick()" accesskey="B"><P><U>B</U>ỏ qua</P></Button></td>
		<td width="13%"><Button name="CmdSearch" style="FONT-FAMILY: Arial;WIDTH: 100%" LANGUAGE=javascript onclick="return CmdSearch_onclick()" accesskey="B"><P><U>B</U>ỏ qua</P></Button></td>

		<% if Session("ClsFun").LayGiaTriQuyen(Session("Permision"),Session("FormName"),3)="1" or Session("IsAdmin") then	%>
			<td width="13%"><Button  name="CmdPhannhom" style="FONT-FAMILY:Arial;WIDTH: 100%" LANGUAGE=javascript onclick="return CmdPhannhom_onclick()" accesskey="P"><P><U>P</U>hân nhóm</P></Button></td>
		<%else%>
			<td width="13%"><Button disabled name="CmdPhannhom" Style="FONT-FAMILY:Arial;WIDTH: 100%" LANGUAGE=javascript onclick="return CmdPhannhom_onclick()" accesskey="P"><P><U>P</U>hân nhóm</P></Button></td>				
		<%end if%>
	<%end if%>
  </tr>
</table>
<table border="0" cellspacing="0" style="Font-family:Times New Roman;font-size:12pt;BORDER-BOTTOM-STYLE: solid; BORDER-LEFT-STYLE: solid; BORDER-RIGHT-STYLE: solid; BORDER-TOP-STYLE: none;border-collapse:collapse; border-left-color:#C0C0C0; border-right-color:#C0C0C0; border-top-color:#C0C0C0; border-bottom-color:#C0C0C0" width="100%" bordercolor="#111111" bgcolor="#BDD5D0">
<% if bcomm="detail" then %>
  <tr>
    <td width="15%">&nbsp;Mã</td>
    <td width="15%">
    <input name="TxtMa" disabled=true value="<%=bma%>" maxLength=10 style="FONT-FAMILY: Arial;width:100%" size="20" ></td> 
     <td width="20%" align=right><label for=C1>Ký văn bản&nbsp;</label>
     <%if bKyvanban then %>
		<input name=Kyvanban type=checkbox disabled checked value="ON" id=C1></td>
    <%else%>
		<input name=Kyvanban type=checkbox disabled value="ON" id=C1></td>
    <%end if%>
    <td width="20%" align="center">Ngày thành lập</td>
	<td width="30%">
    <%if bngaytl="" then%>
	    <input type="text" name="TxtNgayTL" disabled=true maxLength=10 style="FONT-FAMILY: Arial;width:100%" LANGUAGE=javascript onkeyup="return TxtNgayTL_onkeyup(this.value)" size="20" ></td>
    <%else%>
    	<input type="text" name="TxtNgayTL" disabled=true value="<%=ClsFun.FormatDate(bngaytl)%>"  maxLength=10 style="FONT-FAMILY: Arial;width:100%" LANGUAGE=javascript onkeyup="return TxtNgayTL_onkeyup(this.value)"></td>
    <%end if%>
  </tr>
  <tr>
    <td width="15%">&nbsp;Tên nhóm</td>
    <td width="30%" colspan=2>
    <input name="TxtTen" disabled=true value="<%=bten%>" maxLength=50 style="FONT-FAMILY: Arial;width:100%" size="20" ></td>
    <td width="20%" align="center">Ngày giải tán</td>
	<td width="30%">
    <%if bngaygt="" then%>
	    <input name="TxtNgayGT" disabled=true maxLength=10 style="FONT-FAMILY: Arial;width:100%" LANGUAGE=javascript onkeyup="return TxtNgayGT_onkeyup(this.value)" size="20"></td>
	<%else%>
		<input name="TxtNgayGT" disabled=true value="<%=ClsFun.FormatDate(bngaygt)%>" maxLength=10 style="FONT-FAMILY: Arial;width:100%" LANGUAGE=javascript onkeyup="return TxtNgayGT_onkeyup(this.value)"></td>
	<%end if%>
  </tr>
  <%else%>  	
  <tr>
    <td width="15%">&nbsp;Mã</td>
    <td width="15%" >
    <input name="TxtMa" disabled=true maxLength=10 style="FONT-FAMILY: Arial;width:100%" size="20" ></td>
    <td width="20%" align=right><label for=C1>Ký văn bản&nbsp;</label><input name=Kyvanban type=checkbox disabled value="ON" id=C1></td>
    <td width="20%" align="center">Ngày thành lập</td>
    <td width="30%">
    <input type="text" name="TxtNgayTL" disabled=true maxLength=10 style="FONT-FAMILY: Arial;width:100%" LANGUAGE=javascript onkeyup="return TxtNgayTL_onkeyup(this.value)" size="20"></td>
  </tr>
  <tr>
    <td width="15%">&nbsp;Tên nhóm</td>
    <td width="30%" colspan=2>
    <input name="TxtTen" disabled=true maxLength=50 style="FONT-FAMILY: Arial;width:100%" size="20" ></td>
    <td width="20%" align="center">Ngày giải tán</td>
    <td width="30%">
    <input name="TxtNgayGT" disabled=true maxLength=10 style="FONT-FAMILY: Arial;width:100%" LANGUAGE=javascript onkeyup="return TxtNgayGT_onkeyup(this.value)" size="20"></td>
  </tr>
<%end if%>
</table>
<!-- Danh sach nhom lam viec -->
<table border="0" style="Font-family:Times new roman;font-size:12pt;BORDER-BOTTOM-STYLE: solid; BORDER-LEFT-STYLE: solid; BORDER-RIGHT-STYLE: solid; BORDER-TOP-STYLE: none;Border-color:#C0C0C0" WIDTH="100%">
  <tr>
    <td width="100%" colspan="4" bgcolor="#173584" align="center"><b><font color="#FFFFFF" size="2">DANH SÁCH NHÓM LÀM VIỆC</font></b></td>
  </tr>
  <tr bgcolor="#BDD5D0">
    <td width="10%" align="center"><b>Mã</b></td>
    <td width="50%" align="center"><b>Tên nhóm</b></td>
    <td width="20%" align="center"><b>Ngày thành lập</b></td>
	<td width="20%" align="center"><b>Ngày giải tán</b></td>
  </tr>
  <%	
	If Not Rec.Eof Then
		nRecCount = Rec.RecordCount
		Rec.PageSize = 20
		nPageCount = Rec.PageCount
		If nPage < 1 then
			nPage = 1			
		End If
		if nPage > nPageCount Then
			nPage=nPageCount
		end if
		cnt=(pg-1)*pgsize + 1		    
		STT=1
		rec.AbsolutePage=nPage
		howmanyrecs=0
		do while not Rec.EOF and howmanyrecs<rec.PageSize
			if (cnt/2=int(cnt/2)) then
				color="#eeeecc"
			else
				color="#F8F9D9"
			end if
%>  
  <tr id=mnu_<%=STT%> style="BORDER-RIGHT: #e7e7e7 1px solid; BORDER-TOP: #e7e7e7 1px solid; BORDER-LEFT: #e7e7e7 1px solid; COLOR: #666666; BORDER-BOTTOM: #e7e7e7 1px solid; HEIGHT: 21px; BACKGROUND-COLOR: <%=color%>" onmouseover="javascript:MouseOverMenu('mnu_<%=STT%>')" onmouseout="javascript:MouseOutMenu('mnu_<%=STT%>','<%=color%>')">
	 <%if Rec("kyvanban")=true then%>
		<td width="10%" style="FONT-FAMILY:Times New Roman; FONT-WEIGHT: bold"><a style='text-decoration: none;color:blue' href="frmnhom.asp?page=<%=nPage%>&bma=<%=Rec("Manhom")%>&bComm=<%="detail"%>">&nbsp;<%=Rec("Manhom")%></a></td>
		<td width="50%" style="FONT-FAMILY:Times New Roman; FONT-WEIGHT: bold"><a style='text-decoration: none;color:blue' href="frmnhom.asp?page=<%=nPage%>&bma=<%=Rec("Manhom")%>&bComm=<%="detail"%>"><%=Rec("tennhom")%></a></td>
	<%else%>
		<td width="10%" style="FONT-FAMILY:Times New Roman;"><a style='text-decoration: none;color:blue' href="frmnhom.asp?page=<%=nPage%>&bma=<%=Rec("Manhom")%>&bComm=<%="detail"%>">&nbsp;<%=Rec("Manhom")%></a></td>	
    		<td width="50%" style="FONT-FAMILY:Times New Roman;"><font face="Time New Roman"><a style='text-decoration: none;color:blue' href="frmnhom.asp?page=<%=nPage%>&bma=<%=Rec("Manhom")%>&bComm=<%="detail"%>"><%=Rec("tennhom")%></a></td>
	<%end if%>
	
    <%if not isnull(Rec("Ngaythanhlap")) then%>
		<td width="20%" align=center><font face="Time New Roman"><a style='text-decoration: none;color:blue' href="frmnhom.asp?page=<%=nPage%>&bma=<%=Rec("Manhom")%>&bComm=<%="detail"%>"><%=ClsFun.FormatDate(Rec("Ngaythanhlap"))%></a></font></td>
	<%else%>
		<td width="20%" align=center><font face="Time New Roman"><a style='text-decoration: none;color:blue' href="frmnhom.asp?page=<%=nPage%>&bma=<%=Rec("Manhom")%>&bComm=<%="detail"%>"></a></font></td>
	<%end if%>
	<%if not isnull(Rec("Ngaygiaitan")) then%>
		<td width="20%" align=center><font face="Time New Roman"><a style='text-decoration: none;color:blue' href="frmnhom.asp?page=<%=nPage%>&bma=<%=Rec("Manhom")%>&bComm=<%="detail"%>"><%=ClsFun.FormatDate(Rec("Ngaygiaitan"))%></a></font></td>    
	<%else%>
		<td width="20%" align=center><font face="Time New Roman"><a style='text-decoration: none;color:blue' href="frmnhom.asp?page=<%=nPage%>&bma=<%=Rec("Manhom")%>&bComm=<%="detail"%>"></a></font></td>    
	<%end if%>
  </tr>
<%			STT=STT+1
			Rec.MoveNext
			cnt=cnt+1
			howmanyrecs=howmanyrecs+1
		loop
	end if
	rec.Close
	set rec=nothing
	
%>  
</table>
 <!-- Phan trang -->
<br>
<table width="98%" cellspacing=0 cellpadding=0>
<tr>
<% if nPage > 0  and nPageCount >0 then %>  
	<td width="20%"><b>Trang&nbsp; <%=nPage%>/<%=nPageCount%></b></td>
<!-- 	<td width= "80%" align="right">
	<% if nPageCount > 1 then %>    
		Chuyển nhanh tới trang:&nbsp;
		<select name="page" style="width:45;height:23;font-size:8pt" size=1 onchange="javaScript:ChangePage()">
			<% for i = 1 to nPageCount%>	
				<% if bComm<>"search"  then
					strURL="frmnhom.asp?bsearch="& bsearch &"&Loaitim="& loaitim &"&page="+ cstr(i) + "&bComm="
				else
					strURL="frmnhom.asp?bsearch="& bsearch &"&Loaitim="& loaitim &"&page="+ cstr(i) + "&bComm=search"
				end if %>
				<option value="<%=strURL%>" <%=chkSelected(i, nPage)%>><%=i%></option>
			<% next %>    
		</select>
		</td>                                  
	<% end if %> -->             
<% 'else %>
<% end if %>
<td width= "80%" align="center"><%=Paging(nPage, nPageCount, nRecCount)%></td>
</tr>
</table>
</body>
</form>
</html>
<%
	Conn.Close
	Set Conn=nothing
	set ClsFun=nothing
%>